<?php

class Video_item_Controller extends Base_Controller {

    public function action_list() {

        $per_page = Input::get('per_page', 20);
        $videoLogic = new VideoLogic();
        $ret = $videoLogic->getVideolist($per_page);
        unset($videoLogic);
        return Response::json($ret);
    }

    //list item
    public function action_retrieve() {
        if (!Input::has('videoID')) {
            return Response::json(array(
                        'errno' => UMSErrcode::PARA_ERR,
            ));
        }
        $videoID = intval(Input::get('videoID'));
        $videoLogic = new VideoLogic();
        $ret = $videoLogic->getVideoInfoByID($videoID);
        unset($videoLogic);
        if (false === $ret) {
            return Response::json(array());
        }
        return Response::json($ret);
    }

    public function action_add() {
        if (!Input::has('videoID') || !Input::has('title') || !Input::has('desc') || !Input::has('cid') ||
                !Input::has('duration') || !Input::has('image') || !Input::has('price') || !Input::has('type') ||
                !Input::has('so') || !Input::has('status')) {
            return Response::json(array(
                        'errno' => UMSErrcode::PARA_ERR,
            ));
        }
        $videoID = intval(Input::get('videoID'));
        $title = Input::get('title');
        $desc = Input::get('desc');
        $cid = Input::get('cid');
        $duration = Input::get('duration');
        $image = Input::get('image');
        $price = intval(Input::get('price'));
        $type = intval(Input::get('type'));
        $sort_order = intval(Input::get('so'));
        $status = intval(Input::get('status'));
        $videoLogic = new VideoLogic();
        $ret = $videoLogic->addVideoInfo($title, $desc, $cid, $duration, $image, $price, $type, $sort_order, $status);
        unset($videoLogic);
        if ($ret) {
            Response::json(
                    array(
                        'errno' => UMSErrcode::SUCCESS,
            ));
        } else {
            Response::json(
                    array(
                        'errno' => UMSErrcode::SYS_ERR,
            ));
        }
    }

    //更新普通信息
    public function action_updateinfo() {
        if (!Input::has('videoID') || !Input::has('title') || !Input::has('cid') || !Input::has('duration') ||
                !Input::has('image') || !Input::has('price') || !Input::has('type') || !Input::has('so') ||
                !Input::has('status')) {
            return Response::json(array(
                        'errno' => UMSErrcode::PARA_ERR,
            ));
        }
        $videoID = intval(Input::get('videoID'));
        $title = Input::get('title');
        $cid = Input::get('cid');
        $duration = Input::get('duration');
        $image = Input::get('image');
        $price = intval(Input::get('price'));
        $type = intval(Input::get('type'));
        $sort_order = intval(Input::get('so'));
        $status = intval(Input::get('status'));

        $videoLogic = new VideoLogic();
        $ret = $videoLogic->updateVideCommInfo($videoID, $title, $cid, $duration, $image, $price, $type, $sort_order, $status);
        unset($videoLogic);
        if ($ret) {
            Response::json(
                    array(
                        'errno' => UMSErrcode::SUCCESS,
            ));
        } else {
            Response::json(
                    array(
                        'errno' => UMSErrcode::SYS_ERR,
            ));
        }
    }

    //更新视频描述
    public function action_updatedesc() {
        if (!Input::has('videoID') || !Input::has('desc')) {
            return Response::json(array(
                        'errno' => UMSErrcode::PARA_ERR,
            ));
        }
        $videoID = intval(Input::get('videoID'));
        $desc = Input::get('desc');
        $tag = '';
        if (Input::has('tag')) {
            $tag = Input::get('tag');
        }
        $videoLogic = new VideoLogic();
        $ret = $videoLogic->updateVideoDesc($videoID, $desc, $tag);
        if ($ret) {
            Response::json(array(
                'errno' => UMSErrcode::SUCCESS,
            ));
        } else {
            Response::json(array(
                'errno' => UMSErrcode::SYS_ERR,
            ));
        }
    }

}

?>
